package fun.tan90.easy.binlog.manager.rest;

import fun.tan90.easy.binlog.base.convention.Res;
import fun.tan90.easy.binlog.base.convention.page.SimplePage;
import fun.tan90.easy.binlog.manager.model.cmd.BinlogOutputAddCmd;
import fun.tan90.easy.binlog.manager.model.cmd.BinlogOutputPageCmd;
import fun.tan90.easy.binlog.manager.model.cmd.BinlogOutputUpdateCmd;
import fun.tan90.easy.binlog.manager.model.vo.BinlogOutputInfoVo;
import fun.tan90.easy.binlog.manager.model.vo.BinlogOutputPageVo;
import fun.tan90.easy.binlog.manager.service.BinlogOutputService;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;

/**
 * 控制层。
 *
 * @author 陈浩杰
 * @since 2023-09-12
 */
@RestController
@RequestMapping("/binlog-output")
public class BinlogOutputController {

    @Resource
    BinlogOutputService binlogOutputService;

    @GetMapping("{id}")
    public BinlogOutputInfoVo info(@PathVariable String id) {
        return binlogOutputService.info(id);
    }

    @PostMapping
    public String addBinlogOutput(@RequestBody @Validated BinlogOutputAddCmd addCmd) {
        return binlogOutputService.addBinlogOutput(addCmd);
    }

    @PutMapping
    public void updateBinlogOutput(@RequestBody @Validated BinlogOutputUpdateCmd updateCmd) {
        binlogOutputService.updateBinlogOutput(updateCmd);
    }

    @PostMapping("paging")
    public Res<SimplePage<BinlogOutputPageVo>> paging(@RequestBody @Validated BinlogOutputPageCmd queryCmd) {
        return binlogOutputService.paging(queryCmd);
    }

    @PutMapping("/switch-status/{id}")
    public void switchBinlogOutputStatus(@PathVariable("id") String id) {
        binlogOutputService.switchBinlogOutputStatus(id);
    }

    @DeleteMapping("/{id}")
    public void delBinlogOutput(@PathVariable("id") String id) {
        binlogOutputService.delBinlogOutput(id);
    }

    @PostMapping("/test")
    public String test(String outputType, @RequestBody String params) {
        return binlogOutputService.test(outputType, params);
    }
}
